package com.naire.modul.project.action;

import java.util.ArrayList;
import java.util.List;

import net.common.action.GeneralAction;

import com.naire.modul.projecperiods.vo.ProjecperiodsVo;
import com.naire.modul.project.service.ProjectDeleteService;
import com.naire.modul.project.service.ProjectEditorService;
import com.naire.modul.project.service.ProjectFindService;
import com.naire.modul.project.service.ProjectSearchService;
import com.naire.modul.project.service.ProjectStopService;
import com.naire.modul.project.vo.ProjectVo;

public class ProjectAction extends GeneralAction {

	private static final long serialVersionUID = 7127573666355745443L;

	private ProjectVo bean = new ProjectVo();
	private List<ProjectVo> list = new ArrayList<ProjectVo>();
	private List<ProjecperiodsVo> voes = new ArrayList<ProjecperiodsVo>();

	public String search() throws Exception {
		ProjectSearchService service = new ProjectSearchService();
		service.setPageBean(pageBean);
		service.invoke();
		list = service.getList();
		return SUCCESS;
	}

	public String editor() throws Exception {
		Integer projectId = bean.getProject_id();
		ProjectEditorService service = new ProjectEditorService();
		service.setBean(bean);
		service.invoke();
		if (projectId != null) {
			return SUCCESS;
		} else {
			voes = service.getVoes();
			bean.setProject_id(service.getProject_id());
			return "periods";
		}
	}

	public String find() throws Exception {
		if (bean.getProject_id() != null) {
			ProjectFindService service = new ProjectFindService();
			service.setId(bean.getProject_id());
			service.invoke();
			bean = service.getBean();
		}
		return SUCCESS;
	}

	public String stop() throws Exception {
		ProjectStopService service = new ProjectStopService();
		service.setBean(bean);
		service.invoke();
		return SUCCESS;
	}

	public String delete() throws Exception {
		ProjectDeleteService service = new ProjectDeleteService();
		service.setBean(bean);
		service.invoke();
		return SUCCESS;
	}

	public ProjectVo getBean() {
		return bean;
	}

	public void setBean(ProjectVo bean) {
		this.bean = bean;
	}

	public List<ProjectVo> getList() {
		return list;
	}

	public void setList(List<ProjectVo> list) {
		this.list = list;
	}

	public List<ProjecperiodsVo> getVoes() {
		return voes;
	}

	public void setVoes(List<ProjecperiodsVo> voes) {
		this.voes = voes;
	}
}
